package com.itheima.网络编程.tcp编程.tcp编程.文件上传线程池二;

import java.io.*;
import java.net.Socket;
import java.util.UUID;

public class ThreadTcp implements Runnable {
    Socket sk;

    public ThreadTcp(Socket sk) {
        this.sk = sk;
    }

    @Override
    public void run() {
        try {
            BufferedWriter bw = new BufferedWriter(new FileWriter
                    ("C:\\Users\\身体和心灵\\Desktop\\图片\\"
                            + UUID.randomUUID().toString() + ".txt"));
            BufferedReader br = new BufferedReader(new
                    InputStreamReader(sk.getInputStream()));
            String str;
            while ((str = br.readLine()) != null) {
                bw.write(str);
                bw.newLine();
                bw.flush();
            }
            System.out.println("==========================================================");
            BufferedWriter bwServer = new BufferedWriter(new
                    OutputStreamWriter(sk.getOutputStream()));
            bwServer.write("===================上传成功==================");
            bwServer.close();
            bw.close();
            br.close();
            sk.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
